package com.lex.controller;

import com.lex.common.annoatation.SysLog;
import com.lex.common.api.CommonResult;
import com.lex.common.enums.BusinessType;
import com.lex.data.admin.model.LexSysDictData;
import com.lex.data.admin.model.LexSysDictType;
import com.lex.entity.params.DictDataQueryParams;
import com.lex.entity.params.DictDataStatusQuery;
import com.lex.entity.params.DictTypeQueryParams;
import com.lex.entity.params.DictTypeStatusQuery;
import com.lex.service.DictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Schema(name = "DictController", description = "字典类型表")
@Tag(name = "DictController", description = "字典类型表")
@RequestMapping("/dict")
public class DictController {

    @Autowired
    private DictService dictService;

    /**
     * 新增字典类型
     */
    @Operation(summary = "新增字典类型")
    @SysLog(title = "新增字典类型",businessType = BusinessType.INSERT)
    @RequestMapping(value = "/createType",method = RequestMethod.POST)
    public CommonResult createType(@RequestBody LexSysDictType dictType) {
        return dictService.createType(dictType);
    }
    /**
     * 修改字典类型
     */
    @Operation(summary = "修改字典类型")
    @SysLog(title = "修改字典类型",businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateType",method = RequestMethod.PUT)
    public CommonResult updateType(@RequestBody LexSysDictType dictType) {
        return dictService.updateType(dictType);
    }
    /**
     * 删除字典类型
     */
    @Operation(summary = "删除字典类型")
    @SysLog(title = "删除字典类型",businessType = BusinessType.DELETE)
    @RequestMapping(value = "/deleteType/{dict_id}",method = RequestMethod.DELETE)
    public CommonResult deleteType(@PathVariable Long dict_id) {
        return dictService.deleteType(dict_id);
    }
    /**
     * 获取所有字典类型列表
     */
    @Operation(summary = "获取所有字典类型列表")
    @RequestMapping(value = "/allDictListType",method = RequestMethod.GET)
    public CommonResult allDictListType(@Validated DictTypeQueryParams queryParamsDto,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        @RequestParam(defaultValue = "1") Integer page) {
        return dictService.allDictListType(queryParamsDto,pageSize,page);
    }
    /**
     * 获取所有字典数据列表
     */
    @Operation(summary = "获取所有字典数据列表")
    @RequestMapping(value = "/allDictListData",method = RequestMethod.GET)
    public CommonResult allDictListData(@Validated  DictDataQueryParams query,
                                        @RequestParam(defaultValue = "10") Integer pageSize,
                                        @RequestParam(defaultValue = "1") Integer page) {
        return dictService.allDictListData(query,pageSize,page);
    }
    /**
     * 新增字典数据
     */
    @Operation(summary = "新增字典数据")
    @SysLog(title = "新增字典数据",businessType = BusinessType.INSERT)
    @RequestMapping(value = "/createData",method = RequestMethod.POST)
    public CommonResult createData(@RequestBody LexSysDictData dictType) {
        return dictService.createData(dictType);
    }
    /**
     * 修改字典数据
     */
    @Operation(summary = "修改字典数据")
    @SysLog(title = "修改字典数据",businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateData",method = RequestMethod.PUT)
    public CommonResult updateData(@RequestBody LexSysDictData dictType) {
        return dictService.updateData(dictType);
    }
    /**
     * 删除字典数据
     */
    @Operation(summary = "删除字典数据")
    @SysLog(title = "删除字典数据",businessType = BusinessType.DELETE)
    @RequestMapping(value = "/deleteData/{dict_code}",method = RequestMethod.DELETE)
    public CommonResult deleteData(@PathVariable Long dict_code) {
        return dictService.deleteData(dict_code);
    }
    /**
     * 更新数据字典类型状态
     */
    @Operation(summary = "更新数据字典类型状态")
    @SysLog(title = "更新数据字典类型状态",businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateTypeStatus",method = RequestMethod.PUT)
    public CommonResult updateTypeStatus(@RequestBody DictTypeStatusQuery dictTypeStatusQuery) {
        return dictService.updateTypeStatus(dictTypeStatusQuery);
    }
    /**
     * 更新数据字典数据状态
     */
    @Operation(summary = "更新数据字典数据状态")
    @SysLog(title = "更新数据字典数据状态",businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateDataStatus",method = RequestMethod.PUT)
    public CommonResult updateDataStatus(@RequestBody DictDataStatusQuery dictTypeStatusQuery) {
        return dictService.updateDataStatus(dictTypeStatusQuery);
    }
    /**
     * 根据字典类型获取字典数据
     */
    @Operation(summary = "根据字典类型获取字典数据")
    @RequestMapping(value = "/getDictData",method = RequestMethod.GET)
    public CommonResult getDictDataByType(@RequestParam(name = "dictType", required = true) String dictType) {
        return dictService.getDictDataByType(dictType);
    }
}
